package com.parktech.sun.web.controller;

import com.parktech.sun.domain.model.Constants;
import com.parktech.sun.domain.repository.Page;
import com.parktech.sun.domain.service.industryprealert.IndustryPrealertService;
import com.parktech.sun.domain.service.industryservice.IndustryServiceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * User: Think
 * Date: 11-1-18
 * Time: 上午7:10
 */
@Controller
public class IndustryPrealertViewController extends BaseViewController {

    private int pageSize = Constants.PAGINATION_PAGE_SIZE;

    private IndustryPrealertService industryPrealertService;

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    @Autowired
    public IndustryPrealertViewController(IndustryPrealertService industryPrealertService) {
        this.industryPrealertService = industryPrealertService;
    }

    @RequestMapping("/prealerts/{prealertId}")
    public String viewDetail(@PathVariable Long prealertId, Model model) {
        model.addAttribute(industryPrealertService.getById(prealertId));
        return "prealertDetail";
    }
    @RequestMapping("/prealerts/pages/{pageNo}")
    public String viewPage(@PathVariable int pageNo, Model model) {
        Page page = new Page(pageSize, pageNo);
        model.addAttribute(industryPrealertService.pageBy(page));
        return "prealerts";
    }
}
